﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Chaine
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "WebEventsIndex",
                "events/Now",
                new { controller = "WebEvents", action = "Now" }
                );

            routes.MapRoute(
                "WebEvents",
                "events/{year}",
                new { controller = "WebEvents", action = "index", year = UrlParameter.Optional },
                new { year = @"^\d{4}$" }
                );

            routes.MapRoute(
                "WebEvent",
                "events/{date}",
                new { controller = "WebEvents", action = "detail" },
                new { date = @"^\d{8}$" }
                );

            routes.MapRoute(
                "AdminEvent",
                "system/admin/event/{action}/{id}",
                new { controller = "AdminEvent", action = "index", id = UrlParameter.Optional });

            routes.MapRoute(
                "AdminPoster",
                "system/admin/poster/{action}/{eventid}",
                new { controller = "AdminPoster", action = "delete", id = UrlParameter.Optional });

            routes.MapRoute(
                "AdminPhoto",
                "system/admin/photo/{eventid}/{action}/{filename}",
                new { controller = "AdminPhoto", action = "index", filename = UrlParameter.Optional }
                );

            routes.MapRoute(
                "AdminEmail",
                "system/admin/email/{action}/{id}",
                new { controller = "AdminEmail", action = "index", id = UrlParameter.Optional }
                );

            routes.MapRoute(
                "AdminMember",
                "system/admin/member/{action}/{id}",
                new { controller = "AdminMember", action = "index", id = UrlParameter.Optional }
                );

            routes.MapRoute(
                "Account",
                "system/Account/{action}/{id}",
                new { controller = "Account", action = "index", id = UrlParameter.Optional }
                );

            routes.MapRoute(
                "Home",
                "system/{controller}/{action}",
                new { controller = "Account", action = "Profile" }
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            GlobalFilters.Filters.Add(new ValidateInputAttribute(false));

            //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
        }
    }
}